<template>
  <ui-page ref="dataList" class="mine" :bg-color="true">
    <view class="mine__profile" @click="handleProfileClick">
      <view class="mine__profile-avatar">
        <ui-avatar :src="currentUser.avatar" size="large"></ui-avatar>
      </view>
      <view class="mine__profile-main">
        <view class="mine__profile-name">{{ currentUser.nickName }}</view>
        <view class="mine__profile-tips">查看个人资料与更多设置</view>
      </view>
    </view>
    <view class="mine__menu">
      <ui-form>
        <view style="display: flex;background-color: white;margin: 10rpx 0rpx;border-radius: 20rpx;padding: 10rpx 30rpx">
          <image :src="indexMyaoqingImage" style="width: 40rpx;height: 40rpx;padding-top: 35rpx"></image>
          <ui-form-item style="flex: 1;font-size: 25rpx"
                        :show-arrow="true"
                        label="人员管理"
                        @click="handlePeopleManageClick"
          >
            <view style="float: left;color: #F47554;font-size: 22rpx;padding-top: 15rpx">
              (管理业务、协同等人员！)
            </view>
          </ui-form-item>
        </view>
        <view style="display: flex;background-color: white;margin: 10rpx 0rpx;border-radius: 20rpx;padding: 10rpx 30rpx">
          <image :src="indexClockImage" style="width: 40rpx;height: 40rpx;padding-top: 35rpx"></image>
          <ui-form-item style="flex: 1"
                        :show-arrow="true"
                        label="时间显示"
                        @click="handleClockSettingClick"
          >
          </ui-form-item>
        </view>
        <view style="display: flex;background-color: white;margin: 10rpx 0rpx;border-radius: 20rpx;padding: 10rpx 30rpx">
          <image :src="indexShezhimage" style="width: 40rpx;height: 40rpx;padding-top: 35rpx"></image>
          <ui-form-item style="flex: 1"
                        :show-arrow="true"
                        label="我的设置"
                        @click="handleProfileClick"
          >
          </ui-form-item>
        </view>
      </ui-form>
    </view>
    <view class="mine__actions">
      <ui-button block type="primary" @click="handleLogoutClick"
      >退出登录</ui-button
      >
    </view>
    <ui-popup v-model="showServicePopup" type="center">
      <mine-service @confirm="handleConfirmClick"></mine-service>
    </ui-popup>

    <view class="mine__tips" v-if="!hideTips">
      <bi-follow-official-account
          v-if="!checkFlag"
          @close="handleCloseTips"
      ></bi-follow-official-account>
    </view>

  </ui-page>
</template>

<script>
import { mapGetters, mapActions } from 'vuex';
import MineService from './mine-service.vue';
import BiFollowOfficialAccount from '@/common/follow-official-account/follow-official-account.vue';
import { getShareData } from '@/utils/share.js';
import { getLoginUser } from '@/apis/account.js';
import { checkIfAttention } from '@/apis/order.js';

export default {
  components: {
    MineService,
    BiFollowOfficialAccount
  },
  data() {
    return {
      kefuVisible:false,
      indexMapImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/my-device.png',
      indexShoucangImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/my-shoucang.png',
      indexliulanjiluImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/liulanjilu.png',
      indexYaoqingImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/yaoqing.png',
      indexMyaoqingImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/wodeyaoqing.png',
      indexKefuImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/kefu.png',
      indexXieyimage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/xieyi.png',
      indexShezhimage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/mysetip.png',
      indexClockImage: 'https://hsmw-tool-pic-1303885219.cos.ap-beijing.myqcloud.com/weapp/files/htn/clock.png',
      checkFlag:true,
      hideTips: false,
      showServicePopup: false,
      isType:null,
      showShenhe:false
    };
  },
  computed: {
    ...mapGetters(['currentUser']),
    ...mapGetters(['isLogin'])
  },
  onShareAppMessage() {
    return getShareData();
  },
  onShow() {
  },
  onLoad() {
    if (!this.isLogin) {
      uni.redirectTo({
        url: '/pages/login/login?returnUrl='+'\/pages\/mine\/mine'
      })
      setTimeout(() => {
        uni.showToast({
          icon: 'none',
          title: '您当前未登录，请登录后再查看我的信息,已为您跳转到登录页面！',
          slideDuration:1000
        })
        //error('您当前未登录, 正在为您跳转到登录页面!')
      }, 1500)
    }else {
      getLoginUser().then((res)=>{
        this.isType=res.type
        if (res.deptId===1){
          this.showShenhe=true
        }
      })
    }

  },
  methods: {
    handleShowCode() {
      this.showServicePopup = true
    },
    ...mapActions(['SetUserLogout']),
    handleCloseTips() {
      this.hideTips = true;
    },
    handleServiceClick() {
      this.showServicePopup = true;
    },
    handleMyVehicleClick() {
      uni.navigateTo({
        url: '/pages/vehicle-my/vehicle-my'
      });
    },
    handleScVehicleClick() {
      uni.navigateTo({
        url: '/pages/vehicle-sc/vehicle-sc'
      });
    },
    handleSeeVehicleClick() {
      uni.navigateTo({
        url: '/pages/vehicle-see/vehicle-see'
      });
    },
    handleShenheVehicleClick() {
      uni.navigateTo({
        url: '/packages/mine/sell/sell-shenhe'
      });
    },
    handleClockSettingClick() {
      uni.navigateTo({
        url: '/packages/mine/mine-setting/mine-setting-clock'
      });
    },
    handleYinsiClick() {
      uni.navigateTo({
        url: '/packages/agreement/agreement-privacy/agreement-privacy'
      });
    },
    handleInviteClick() {
      uni.navigateTo({
        url: '/pages/invite/invite'
      });
    },
    handleProfileClick() {
      uni.navigateTo({
        url: '/packages/mine/mine-setting/mine-setting'
      });
    },
    handleDataCountClick() {
      uni.navigateTo({
        url: '/packages/mine/mine-data/mine-data'
      });
    },
    handleCarManageClick() {
      uni.navigateTo({
        url: '/packages/mine/mine-car/mine-car'
      });
    },
    handlePeopleManageClick() {
      uni.navigateTo({
        url: '/packages/mine/mine-people/mine-people'
      });
    },
    handleBelongCompanyClick() {
      uni.navigateTo({
        url: '/packages/mine/mine-company/mine-company'
      });
    },
    handleprojManageClick() {
      uni.navigateTo({
        url: '/packages/project/project/project'
      });
    },
    handleCompanyClick() {
      uni.navigateTo({
        url: '/packages/common/involved-select/mine-involved'
      });
    },
    handleConfirmClick() {
      this.showServicePopup = false;
    },
    handleLogoutClick() {
      return this.SetUserLogout().then(() => {
        uni.reLaunch({
          url: '/pages/home/home'
        });
      });
    }
  }
};
</script>

<style lang="less">
.mine {
  position: relative;
}
.mine__profile {
  display: flex;
  flex-direction: row;
  background-color: #fff;
  padding: 16px 36px 16px 16px;
  line-height: 1.7em;
  position: relative;
  &:active {
    background-color: rgba(0, 0, 0, 0.06);
  }
  &:after {
    content: '';
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%) rotate(45deg);
    border: 1px solid #ddd;
    width: 8px;
    height: 8px;
    border-left: 0;
    border-bottom: 0;
  }
}
.mine__profile-avatar {
  margin-right: 16px;
}
.mine__profile-main {
  padding: 4px 0;
}
.mine__profile-name {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 2px;
}
.mine__profile-tips {
  color: #666666;
  font-size: 12px;
}
.mine__tips {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 16px;
}
.mine__menu {
  margin-top: 16px;
}
.mine__actions {
  padding: 16px;
}
</style>
